<template>
  <!--故障管理--维修列表-->
  <div class="content-area">
    <!-- 位置模块 -->
    <HeadTop></HeadTop>
    <div class="search-area">
      <div class="search-content">
        <div class="search-item">
          <span>注册代码:</span>
          <el-input placeholder="请输入内容" v-model="searchMsg.elCode" clearable>
          </el-input>
        </div>
        <div class="search-item">
          <unit-data @curName="get" @setStatus="set" :childName="parentName" :searchType="1"
                     @setInputEmpty="setInputEmpty"></unit-data>
        </div>
        <div class="search-item search-time"><span>开始时间:</span>
          <el-date-picker value-format='yyyy-MM-dd' v-model="searchMsg.startDate" align="right" type="date"
                          placeholder="选择开始时间">
          </el-date-picker>
        </div>
        <div class="search-item search-time"><span>结束时间:</span>
          <el-date-picker value-format='yyyy-MM-dd' v-model="searchMsg.endDate" align="right" type="date"
                          placeholder="选择结束时间">
          </el-date-picker>
        </div>
        <div class="search-item">
          <span>维修状态:</span>
          <el-select v-model="searchMsg.repStatus" placeholder="请选择">
            <el-option v-for="item in searchData.statusArr" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
        <areaSelect v-on:getNowAreaPosition="getArea" :areaText="areaText"></areaSelect>
      </div>
      <div class="search-footer">
        <button class="search-btn" @click="searchServiceListsData">查询</button>
      </div>
    </div>

    <!--内容-->
    <div class="main-content">
      <div class="content-info">

        <!-- 111:表格数据与翻页合并模块 -->
        <DataTable :dataTableObj="dataTableObj" :childLoad="parentLoad" v-on:getPageNo="searchByPageNo"  v-on:handlePageReload="pageReload"
                   v-on:getPageSize="searchByPageSize">

          <!--除查询外的操作-->
          <div slot="operate">
            <div class="some-operate">
              <!--<button class="some-btn">导出</button>-->
            </div>
          </div>
          <!-- 额外的操作以及其他因素 -->
          <div>
            <el-table-column fixed="right" align="center" label="操作" width="70">
              <template slot-scope="scope">
                <div class="item-route">
                  <div class="item-route-link" v-for="(item ,index ) in childLink" v-if="pagePower['003002001']"
                       @click="$goRoute( item.route +'?id='+ scope.row.id)">{{item.text}}
                  </div>
                </div>
              </template>
            </el-table-column>
          </div>

        </DataTable>
      </div>
    </div>
  </div>
</template>
<script>
  // 表格数据
  import DataTable from "../../../components/dataTable/dataTable"
  import areaSelect from "../../../components/areaSelect/areaSelect"
  import com from '../../../js/common'
  // 时间插件
  import moment from 'moment'
  import HeadTop from "../../../components/head-top/head-top"
  import unitData from "../../../components/unitData/unitData" // 维保单位/物业单位(建议输入数据显示)
  import {getServiceList} from '@/api/getData'

  export default {
    name: 'serviceLists',
    components: {
      DataTable,
      areaSelect,
      HeadTop,
      unitData
    },
    data() {
      return {
        pagePower: JSON.parse(com.getStore('pagePowers'))['003002'] ? JSON.parse(com.getStore('pagePowers'))['003002'] : {}, // 权限
        parentLoad: '加载中...',    // 加载状态
        parentName: "维保单位",  // 父组件名称(维保单位或者物业单位)
        // 区域选择
        areaText: '区域选择:',
        //子页面信息
        childLink: [
          {
            route: '/manage/faultMgr/serviceLists/serviceDetail',
            text: '查看详情'
          }
        ],
        //  111:表格组件数据
        dataTableObj: {
          // 表格数据
          tableData: [],
          // 表格标题
          tableColumns: [
            {
              text: '序号',
              width: '25',
              attributeName: 'index'
            },
            {
              text: '注册代码',
              width: '90',
              attributeName: 'elCode'
            },
            {
              text: '电梯类型',
              width: '60',
              attributeName: 'elTypeName'
            },
            {
              text: '创建时间',
              width: '80',
              attributeName: 'repEndDate'
            },
            {
              text: '维修责任人',
              width: '60',
              attributeName: 'repUserName'
            },
            {
              text: '故障来源',
              width: '70',
              attributeName: 'sourceName'
            },
            {
              text: '维保单位',
              width: '120',
              attributeName: 'elMaintaimName'
            },
            {
              text: '安装地址',
              width: '150',
              attributeName: 'elArea'
            },
            {
              text: '状态',
              width: '70',
              attributeName: 'repStatusName'
            }
          ],
          // 翻页的数据
          pageObj: {
            // 每页分为几条数据
            pageSize: 10,
            // 总共多少数据
            pageNum: 0,
            pageNo: 1,
            searchStatus: 2,
          },
        },
        searchData: { // 输入字段(前端字段)
          elCode: '',       // 注册代码
          elMaintainId: '',  // 维保单位
          startDate: '',    // 开始时间
          endDate: '',      // 结束时间
          repStatus: '',    // 状态
          elAreaCode: '', // 查询地区code
          statusArr: [
            {
              value: '',
              label: '全部状态'
            },
            {
              value: '2',
              label: '待维修'
            },
            {
              value: '3',
              label: '维修中'
            },
            {
              value: '4',
              label: '已维修待评定'
            }
          ]
        },
        searchMsg: { // 输入字段(后台字段)
          elCode: '',       // 注册代码
          maintainDepCode: '',  // 维保单位
          startDate: '',    // 开始时间
          endDate: '',      // 结束时间
          repStatus: '',    // 状态
          elAreaCode: '', // 查询地区code
        }
      }
    },
    created() {
      // 获取当前页面所需数据
      this.getServiceListsData()
    },
    methods: {
      get(msg) { // 获取到子组件的数据
        this.searchMsg.maintainDepCode = msg
      },
      set() {
        this.searchMsg.maintainDepCode = -1
      },
      // 前后信息不同时置空查询条件
      setInputEmpty() {
        this.searchMsg.maintainDepCode = ''
      },
      // 获取页面数据
      getServiceListsData(obj) { // 获取页面所需数据
        this.dataTableObj.pageObj.searchStatus = 2
        this.dataTableObj.tableData = []
        let self = this
        getServiceList({
          pageNo: self.dataTableObj.pageObj.pageNo,
          pageSize: self.dataTableObj.pageObj.pageSize,
          condition: self.searchMsg // 输入参数
        }).then(function (data) {
          self.dataTableObj.pageObj.searchStatus = 1
          let info = data.data.data;
          let infoArr = info.data;
          if (infoArr.length > 0) {
            infoArr.forEach((i, t) => {
              i.index = (t + 1) + self.dataTableObj.pageObj.pageSize * (self.dataTableObj.pageObj.pageNo - 1);
              i.auditDate = moment.unix(i.auditDate / 1000).format('YYYY-MM-DD');
              i.repStartDate = moment.unix(i.repStartDate / 1000).format('YYYY-MM-DD');
              i.repEndDate = moment.unix(i.createDate / 1000).format('YYYY-MM-DD hh:mm:ss');
              i.sourceName = i.source === '1' ? '物业上报' : (i.source === '2' ? '业主上报' : (i.source === '3' ? '巡检上报' : (i.source === '4' ? '维保上报' : i.source)));
            });
          } else {
            self.parentLoad = '暂无数据'    // loading(暂无数据)
          }

          self.dataTableObj.tableData = infoArr;
          self.dataTableObj.pageObj.pageNum = info.totalRecord;
        }).catch(function (data) {
          self.parentLoad = data.data.message    // loading(查询失败)
          self.dataTableObj.pageObj.searchStatus = 0
        })
      },
      searchByPageSize(val) { // 每页多少内容
        this.dataTableObj.pageObj.pageSize = val;
        this.getServiceListsData()
      },
      searchByPageNo(val) { // 切换第几页
        this.dataTableObj.pageObj.pageNo = val
        this.getServiceListsData()
      },
      searchServiceListsData() {
        // 跳出查询等待框
        if (moment(this.searchData.endDate).isBefore(this.searchData.startDate)) {
          this.$message.warning('开始时间应小于结束时间')
          return
        }
        this.getServiceListsData()
      },
      getArea(res) { // 获取查询地址
        console.log(res);
        this.searchMsg.elAreaCode = res.code
      },

      // 页面刷新
      pageReload(){
        this.getServiceListsData();
      }
    },
  }
</script>
<style lang="scss" type="text/scss">
  @import "../../../style/entry/components/pageCommon";
</style>
